package com.hzz.dao.patrol;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hzz.dto.patrol.PatrolStatDto;
import com.hzz.dto.patrol.PatrolTaskDto;
import com.hzz.entity.patrol.PatrolTask;
import com.hzz.framework.dao.IBaseDao;
import com.hzz.framework.entity.IEntity;

/**
 * <p>
 * 临时巡查任务 数据库处理接口类。
 */
@Mapper
public interface IPatrolTaskDao extends IBaseDao {
    
    /**
     * 判断是否存在
     */
    @Override
    @Select("select IFNULL(count(0),0) as count from patrol_task where  id = #{id} ")
    int isDataExist(IEntity entity) throws Exception;
    
    /**
     * 逻辑删除
     */
    @Override
    @Update("update patrol_task set  date_updated=now(), del_flag=1 where  id = #{id} ")
    int deleteById(IEntity entity) throws Exception;
    
    /**
     * 根据主键 物理删除
     */
    @Override
    @Delete("delete from patrol_task where  id = #{id} ")
    int deleteByPrimaryKey(IEntity entity) throws Exception;
    
    List findListByParam(IEntity entity) throws Exception;
    
    /**
     * 完成情况统计
     * @param entity
     * @return
     * @throws Exception
     */
    List findCompletionStatistics(IEntity entity) throws Exception;
    
    /**
     * 本级河长日志
     * @param entity
     * @return
     * @throws Exception
     */
    List findPatrolTaskLog(IEntity entity) throws Exception;
    
    /**
     * 下级河长日志
     * @param entity
     * @return
     * @throws Exception
     */
    List findPatrolTaskLogJunior(IEntity entity) throws Exception;
    
    /**
     * 查询巡查次数
     * @param entity
     * @return
     * @throws Exception
     */
    Integer getPatrolTimes(IEntity entity) throws Exception;
    
    /**
     * 巡查统计
     * @return
     * @throws Exception
     */
    List patrolStat(PatrolStatDto dto) throws Exception;
    
    /**
     * 查询巡查率前5名
     * @return
     * @throws Exception
     */
    List<HashMap> getInspectionRateDESC() throws Exception;
    
    /**
     * 查询巡查率后5名
     * @return
     * @throws Exception
     */
    List<HashMap> getInspectionRateASC() throws Exception;
    
    /**
     * 查询任务
     * @return
     * @throws Exception
     */
    List<PatrolTaskDto> getList(PatrolTaskDto dto) throws Exception;

    /**
     * 更新同步结果
     */
    @Update("update patrol_task set dsync_state = #{dsyncState} ,dsync_count = dsync_count+1 ,dsync_djson = #{dsyncDjson} , dsync_result = #{dsyncResult} where  id = #{id} ")
    int updateDSync(IEntity entity) throws Exception;

    int dataStatistics(IEntity entity) throws Exception;

    List<PatrolTask> dataFailIsList(IEntity entity) throws Exception;
}